﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace ProDivingAdmin2salmon14
{
    public class Dive
    {
        public string diveCode { get; set; }
        public List<JudgeScore> judgeScores { get; set; }
        public float diveScore { get; set; }

        public Dive()
        {
            this.diveScore = 0;
            this.judgeScores = new List<JudgeScore>();
        }

        public Dive(string diveCode)
        {
            this.diveCode = diveCode;
            this.diveScore = 0;
            this.judgeScores = new List<JudgeScore>();
        }

        public void CalculateScore()
        {
            this.diveScore = 0;
            JudgeScore max = new JudgeScore("", 0);
            JudgeScore min = new JudgeScore("", 10);
            foreach (var judgeScore in this.judgeScores)
            {
                if (judgeScore.score > max.score)
                {
                    max = judgeScore;
                }
                if (judgeScore.score < min.score)
                {
                    min = judgeScore;
                }

                this.diveScore += judgeScore.score;
            }

            this.diveScore -= max.score;
            this.diveScore -= min.score;

            

            if (this.diveScore < 0)
            {
                this.diveScore = 0;
            }
            this.diveScore *= this.GetDifficulty();
        }

        public float GetDifficulty() 
        {
            float difficulty;
            try
            {
                difficulty = Contest.validDives[this.diveCode].Item1;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                
            }
            return difficulty;
        }

        public string GetName() 
        {
            return FileManager.diveList[this.diveCode].Item2;
        }
    }
}
